<?php

App::uses('AppModel', 'Model');

/**
 * Media Model
 *
 * @property Article $Article
 */
class Media extends AppModel {

    /**
     * Display field
     *
     * @var string
     */
    public $displayField = 'filename';
    /**
     * Validation rules
     *
     * @var array
     */
    public $validate = array();
    /**
     * 
     */
    public $actsAs = array(
        'MeioUpload.MeioUpload' => array(
            'filename' => array(
                'Empty' => array('check' => false, 'required' => false),
                'dir' => 'files{DS}articles',
                'allowedMime' => array('application/pdf', 'application/msword'),
                'allowedExt' => array('.pdf', '.doc', '.docx'),
                'maxSize' => 104857600 //100MB
            )
        )
    );


    //The Associations below have been created with all possible keys, those that are not needed can be removed
    /**
     * belongsTo associations
     *
     * @var array
     */
    public $belongsTo = array(
        'Article' => array(
            'className' => 'Article',
            'foreignKey' => 'article_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );
    public function saveMedia($data) {
        
        if (!empty ($data)) {
            $this->create();
            if ($this->save($data) ) {
                return $this->id;
            }
        }
        return false;
    }
    public function updateArticleId($id, $articleId) {
        $this->id = $id;
        $this->saveField('article_id', $articleId);
    }

}
